JavaScript Arrow Function
Arrow function is an alternate to a regular function and in arror function there are no binding of this. In regular function the this keyword represents the object that called the function. The arrow function cannot be used as constructors.
The regular function looks something like below.
Modifying the above function to arrow function
The arrow function will not contain function keyword and it contains arrow representation before the block of statement.
Arrow function with single statement will look something like below.
Example program to know difference between regular function and arrow function.
In the above example, there are two functions one is an arrow function which is arrorDemo() and the other is regular function which is regularDemo() function. The arrowDemo function has been added as event listener to a button with btn_arrow id. Similarly, the regularDemo function has been added as event listener to a button with btn_regular id. Now when clicking the button with btn_regular as id, will return the button object and clicking on the button with btn_arrow as id, will return the window object because, this keyword of arrow function represents the object that defined the arrow function.